home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / BUSINESS / STATA3.LZH / YOURDATA.TUT < prev   
Text File  |  1988-08-29  |  14KB  |  405 lines

  1. set output error
  2. set display page 23
  3. set more 1
  4. #delimit ;
  5.  
  6. di _n(5) in wh
  7. "  ___  ____  ____  ____  ____ tm" _n
  8. " /__    /   ____/   /   ____/" _n
  9. "___/   /   /___/   /   /___/    Entering your data into Stata" _n
  10. "-------------------------------------------------------------"
  11. _n(2) ;
  12.  
  13. di in gr
  14. "In this tutorial we show you how to enter your data into Stata.  The commands"
  15.  _n
  16. "we discuss are:" _n(2)
  17. _col(21) in wh "input          infile" in gr _n(2)
  18. "Before entering data into Stata, clear any data you already have loaded by"
  19. _n
  20. "typing '"
  21. in wh "drop _all" in gr "' and '" in wh "label drop _all" in gr
  22. "'.  The '" in wh "drop _all" in gr "' command tells Stata" _n
  23. "to eliminate any data stored in memory.  The '"
  24. in wh "label drop _all" in gr "' command tells"
  25. _n
  26. "Stata to eliminate any value labels stored in memory, too.  You can learn" _n
  27. "about value labels by typing '" in wh "help label" in gr
  28. "' at the conclusion of this tutorial." _n(5) in wh
  29. ". drop _all" _n(2)
  30. ". label drop _all" ;
  31.  
  32.  
  33. #delimit cr
  34. mac def path
  35. capture run nullfile.tut
  36. if _rc {
  37.     mac def path "\stata\"
  38.     capture run %path`nullfile.tut
  39.     if _rc {
  40.         mac def path "/usr/stata/"
  41.         capture run %path`nullfile.tut
  42.         if _rc {
  43.             #delimit ;
  44.             di in red
  45. "I cannot find the other tutorial files.  I have looked in the current" _n
  46. "directory and in \stata (DOS) or /usr/stata (Unix).  Is Stata installed" _n
  47. "correctly?" _n(2)
  48. "In any case, I cannot run the tutorial." ;
  49.             #delimit cr
  50.             exit
  51.         }
  52.     }
  53. }
  54. macro define F5 "do %path`contents.tut;"
  55. macro define F6 "do %path`yourdata.tut;"
  56. #delimit ;
  57. drop _all ;
  58. label drop _all ;
  59.  
  60. set more 0 ; more ; set more 1 ;
  61.  
  62.  
  63. di _n(2) in wh _dup(79) "-" _n in gr
  64. "The simplest way to enter small data sets into Stata is the '"
  65. in wh "input" in gr "' command." _n
  66. "This command tells Stata that data will be entered from the keyboard.  The"
  67. _n
  68. "syntax is" _n(2)
  69. _col(25) in wh "input " in gr "varlist" _n(2)
  70. "where varlist is a list of the variables you wish to enter.  You will be" _n
  71. "prompted to enter each observation one at a time.  When you have entered all"
  72. _n
  73. "the observations, you type '" in wh "end" in gr "' in lowercase letters." _n(2)
  74. "We will input a small data set containing automobile information.  Let's enter"
  75. _n
  76. "our first car's id code, mileage, weight, and price:" _n
  77. in wh _dup(79) "-" _n(3)
  78. ". input id mpg weight price" _n(2)
  79. in gr _col(13) "id        mpg     weight      price" _n
  80. in bl "  1" in wh ". 1 22 2930 4099" _n
  81. in bl "  2" in wh ". end" _n;
  82. input id mpg weight price;
  83. 1 22 2930 4099;
  84. end;
  85. di ; set more 0 ; more ; set more 1 ;
  86.  
  87. di in wh _dup(79) "-" _n in gr
  88. "If the above appears rather confusing, it is only because it happened so" _n
  89. "quickly." _n(2)
  90. _col(8) "We typed '" in wh "input id mpg weight price" in gr "'." _n(2)
  91. _col(8) "Stata responded by typing a header and then prompting us for the"
  92. _n
  93. _col(8) "first observation." _n(2)
  94. _col(8) "We typed '" in wh "1 22 2930 4099" in gr "' and pressed Return." _n(2)
  95. _col(8) "Stata responded by prompting us for the second observation." _n(2)
  96. _col(8) "We typed '" in wh "end" in gr "' and pressed Return." _n
  97. in wh _dup(79) "-" _n ;
  98. set more 0 ; more ; set more 1 ;
  99.  
  100. di _n(2) in wh _dup(79) "-" _n in gr
  101. "Once we have some data in memory, we can type '"
  102. in wh "input" in gr "' without arguments to add" _n
  103. "more observations:" _n
  104. in wh _dup(79) "-" _n(3)
  105. ". input" _n(2)
  106. in gr _col(13) "id        mpg     weight      price" _n
  107. in bl "  2" in wh ". 2 17 3350 4749" _n
  108. in bl "  3" in wh ". 3 22 2640 3799" _n
  109. in bl "  4" in wh ". 4 20 3250 4816" _n
  110. in bl "  5" in wh ". 5 15 4080 7827" _n
  111. in bl "  6" in wh ". end" _n;
  112.  
  113. input ;
  114. 2 17 3350  4749 ;
  115. 3 22 2640  3799 ;
  116. 4 20 3250  4816 ;
  117. 5 15 4080  7827 ;
  118. end ;
  119.  
  120. di _n in wh _dup(79) "-" _n in gr
  121. "We added four more observations to our data.  Let's '"
  122. in wh "describe" in gr "' and '" in wh "list" in gr "'" _n
  123. "our data just to prove to ourselves that everything worked:" _n
  124. in wh _dup(79) "-" _n(2)
  125. ". describe" ;
  126. set more 0 ; more ; set more 1 ;
  127. noisily describe ;
  128. di _n(2) in wh ". list" ;
  129. noisily list ;
  130. di _n ; set more 0 ; more ; set more 1 ;
  131.  
  132. di _n(2) in wh _dup(79) "-" _n in gr
  133. "You now know how to enter numeric data into Stata." _n(2)
  134. "If our data had contained character variables, however, we would have to do"
  135. _n
  136. "things slightly differently.  Stata has five storage types:" _n(2)
  137. _col(8) in wh "int" _col(16) in gr "integers between -32,768 and 32,766" _n
  138. _col(8) in wh "long" _col(16) in gr
  139. "integers between -2,147,483,648 and 2,147,583,646" _n
  140. _col(8) in wh "float" _col(16) in gr
  141. "floating-point numbers between +/-10^-37 and +/-10^37" _n
  142. _col(8) in wh "double" _col(16) in gr
  143. "floating-point numbers between +/-10^-99 and +/-10^99" _n(2)
  144. _col(8) in wh "str" in gr "#" _col(16) "strings of maximum length #" _n ;
  145.  
  146. di in gr
  147. "When you don't tell Stata what type of variable you are creating, Stata as-" _n
  148. "sumes it is a " in wh "float" in gr "." _n(2)
  149. in wh "str" in gr
  150. "# is not really a storage type, you must substitute a number between "
  151. in wh "2" in gr " and"
  152. _n
  153. in wh "80" in gr
  154. " for the # symbol, producing, for instance, "
  155. in wh "str2" in gr " or " in wh "str10" in gr " or " in wh "str80" in gr "
  156. .  The" _n
  157. "number specifies the maximum width of the string." _n(2)
  158. "Anytime you create a variable, you can specify its storage type by typing the"
  159. _n
  160. "storage type in front of the variable's name." _n
  161. in wh _dup(79) "-" _n ;
  162. set more 0 ; more ; set more 1 ;
  163.  
  164. di _n(2) in wh _dup(79) "-" _n in gr
  165. "Let's try out our newfound knowledge by reentering our automobile data:" _n
  166. in wh _dup(79) "-" _n(2)
  167. ". drop _all" _n(2)
  168. ". input str14 make mpg weight price" _n(2)
  169. in gr _col(13) "make      mpg     weight      price" _n
  170. in bl "  1" in wh ". " _quote "AMC Concord" _quote " 22 2930 4099" _n
  171. in bl "  2" in wh ". " _quote "AMC Pacer" _quote " 17 3350 4749" _n
  172. in bl "  3" in wh ". " _quote "AMC Spirit" _quote " 22 2640 3799" _n
  173. in bl "  4" in wh ". " _quote "Buick Century" _quote " 20 3250 4816" _n
  174. in bl "  5" in wh ". " _quote "Buick Electra" _quote " 15 4080 7827" _n
  175. in bl "  6" in wh ". end" _n;
  176. drop _all;
  177. input str14 make mpg weight price ;
  178. "AMC Concord" 22 2930 4099;
  179. "AMC Pacer" 17 3350 4749;
  180. "AMC Spirit"  22 2640 3799;
  181. "Buick Century" 20 3250 4816;
  182. "Buick Electra" 15 4080 7827;
  183. end;
  184.  
  185. di in wh _dup(79) "-" _n in gr
  186. "The " in wh "str14" in gr
  187. " typed in front of make affected only the make variable, all the re-" _n
  188. "maining variables are " in wh "float" in gr
  189. ".  If we had typed '" in wh "input str14 make int mpg weight" _n
  190. "price" in gr
  191. "', then mpg would have been an " in wh "int" in gr
  192. ", but weight and price would still have" _n
  193. "been " in wh "float" in gr
  194. "s.  Note that we typed double quotes around the strings themselves." _n
  195. in wh _dup(79) "-" _n ;
  196. set more 0 ; more ; set more 1 ;
  197.  
  198. di _n(2) in wh _dup(79) "-" _n in gr
  199. "To prove everything worked, let's " in wh "describe" in gr " and "
  200. in wh "list" in gr " the data:" _n
  201. in wh _dup(79) "-" _n(2)
  202. ". describe" ;
  203. noisily describe ;
  204. di _n in wh ". list" ;
  205. noisily list ;
  206. set more 0 ; more ; set more 1 ;
  207.  
  208. di _n(2) in wh _dup(79) "-" _n in gr
  209. "For larger data sets, typing data from the keyboard is tedious.  Stata can "
  210. "read" _n
  211. "ASCII data files directly from disk with the '" in wh "infile" in gr
  212. "' command.  ASCII data sets" _n
  213. "can be created in your favorite editor or they can be output from another"
  214. " soft-" _n
  215. "ware package." _n(2)
  216. "We have previously created a file called "
  217. in ye "autodata.raw" in gr " using our favorite ed-" _n
  218. "itor.  We'll show you the contents of the file:" _n
  219. in wh _dup(79) "-" _n(2)
  220. ". type %path`autodata.raw" ;
  221. noisily type %path`autodata.raw ;
  222.  
  223. di _n in wh _dup(79) "-" _n in gr
  224. "This is the same data we typed in from the keyboard." _n
  225. in wh _dup(79) "-" _n ;
  226. set more 0 ; more ; set more 1 ;
  227.  
  228. di _n(2) in wh _dup(79) "-" _n in gr
  229. "To input this data from the keyboard, we typed:" _n(2)
  230. _col(8) in wh "input str14 make mpg weight price" _n(2)
  231. in gr "To input it from the file %path`autodata.raw, we type:" _n(2)
  232. _col(8) in wh "infile str14 make mpg weight price using %path`autodata" _n(2)
  233. in wh _dup(79) "-" _n(3)
  234. ". drop _all" _n(2)
  235. ". infile str14 make mpg weight price using %path`autodata" ;
  236. drop _all ;
  237. noisily infile str14 make mpg weight price using %path`autodata ;
  238.  
  239. di _n(2) in wh _dup(79) "-" _n in gr
  240. "Stata read the data from disk.  Once again, let's " in wh "describe"
  241. in gr " and " in wh "list" in gr " the data:" _n
  242. in wh _dup(79) "-" _n(2)
  243. ". describe" ;
  244. set more 0 ; more ; set more 1 ;
  245. noisily describe ;
  246. di _n in wh ". list" ;
  247. noisily list ;
  248. set more 0 ; more ; set more 1 ;
  249.  
  250. di _n(2) in wh _dup(79) "-" _n in gr
  251. "A more advanced method of entering data from disk is to use data dictionaries."
  252. _n
  253. "A dictionary tells Stata the variable names, any formatting information, and"
  254. _n
  255. "labeling.  Dictionaries are useful because they leave behind a permanent rec-"
  256. _n
  257. "ord of the ASCII file's contents." _n(2)
  258. "Dictionaries have too many capabilities to be completely explained here, but"
  259. _n
  260. "you can learn more by typing '"
  261. in wh "help infile" in gr "' at the conclusion of this tutorial." _n
  262. "We will, however, show you two examples.  We have two more files to read, one"
  263. _n
  264. "much like you might create using your word processor or editor, and the second"
  265. _n
  266. "much like a mainframe computer might manufacture." _n ;
  267. di in gr
  268. "The files are called "
  269. in ye "autodata.dct" in gr " and " in ye "mainfram.dct" in gr
  270. ".  Both contain data on the" _n
  271. "same five cars we've used throughout this tutorial." _n
  272. in wh _dup(79) "-" _n(5)
  273. ". drop _all" _n(2)
  274. ". type %path`autodata.dct" ;
  275. set more 0 ; more ; set more 1 ;
  276. drop _all ;
  277. noisily type %path`autodata.dct ;
  278.  
  279. di _n(2) in wh _dup(79) "-" _n in gr
  280. "This is a simple dictionary.  To read the data, we type:" _n
  281. in wh _dup(79) "-" _n(2)
  282. ". infile using %path`autodata.dct" ;
  283. set more 0 ; more ; set more 1 ;
  284. noisily infile using %path`autodata.dct ;
  285. di _n(2) in wh _dup(79) "-" _n in gr
  286. "The data has been read.  We won't bother to prove it, but notice that Stata"
  287. _n
  288. "types the dictionary so that you know what it just read." _n
  289. in wh _dup(79) "-" _n(2)
  290. ". drop _all" ;
  291. drop _all ;
  292. set more 0 ; more ; set more 1 ;
  293.  
  294. di _n(2) in wh _dup(79) "-" _n in gr
  295. "Our last example is more complicated.  The dictionary not only identifies the"
  296. _n
  297. "variables, but it tells Stata how to read them.  The data are run together"
  298. _n
  299. "much like a mainframe computer would do." _n
  300. in wh _dup(79) "-" _n(2)
  301. ". type %path`mainfram.dct" ;
  302. noisily type %path`mainfram.dct ;
  303.  
  304. di in wh _dup(79) "-" _n in gr
  305. "To read the data, we type:" _n
  306. in wh _dup(79) "-" _n(2)
  307. ". infile using %path`mainfram.dct" ;
  308. set more 0 ; more ; set more 1 ;
  309. noisily infile using %path`mainfram.dct ;
  310.  
  311. di _n(4) in wh _dup(79) "-" _n in gr
  312. "The data has now been read.  This time we will prove it:" _n
  313. in wh _dup(79) "-" _n(3)
  314. ". describe" ;
  315. set more 0 ; more ; set more 1 ;
  316. noisily describe ;
  317. di _n in wh ". list" ;
  318. noisily list ;
  319. set more 0 ; more ; set more 1 ;
  320.  
  321. di _n(2) in wh
  322. "Saving data" _n
  323. "-----------" _n ;
  324.  
  325. di in gr
  326. "After you have entered data into Stata, you can save it.  The command is:"
  327. _n(2)
  328. _col(16) in wh "save" in gr " filename" _n(2)
  329. "If you do not specify the extension for the filename, Stata assumes the ex-"
  330. _n
  331. "tension '" in ye ".dta" in gr
  332. "'.  For instance, we could type '" in wh "save auto" in gr
  333. "' to save this data." _n
  334. "It would be saved in the file " in ye "auto.dta" in gr
  335. ".  The command to retrieve previously" _n
  336. "saved data is:" _n(2)
  337. _col(16) in wh "use" in gr " filename [" in wh ", clear" in gr "]" _n(2)
  338. "Thus, the next time we want to use "
  339. in ye "auto.dta" in gr ", we could type '" in wh "use auto"
  340. in gr "' or '" in wh "use" _n
  341. "auto, clear" in gr "'.  Sometimes '" in wh "use auto" in gr
  342. "' will work, but '" in wh "use auto, clear" in gr "' will al-" _n
  343. "ways work.  Stata stores data in memory.  The "
  344. in wh "clear" in gr " option tells Stata that" _n
  345. "it's okay to drop the data in memory in order to retrieve the new data."
  346. _n ;
  347. /*
  348. set more 0 ; more ; set more 1 ;
  349.  
  350. di _n(4) in wh
  351. "Saving data" _n
  352. "-----------" _n ;
  353. */
  354. di in gr
  355. "Although we would like to show you the " in wh "save" in gr
  356. " command, we are not going to." _n
  357. "There are two reasons:" _n ;
  358. set more 0 ; more ; set more 1 ;
  359. di in gr
  360. _col(9) "1.  For those of you who have the full Stata system, we don't" _n
  361. _col(13) "think it would be nice to write on your disk." _n(2)
  362. _col(9) "2.  For those of you who have only the demonstration system, the" _n
  363. _col(13) in wh "save" in gr " command has been removed." ;
  364. set more 0 ; more ; set more 1 ;
  365.  
  366. di _n(4) in wh
  367. "Stat/Transfer" _n
  368. "-------------" _n ;
  369.  
  370. di in gr
  371. "There's one more way to get data into Stata, at least for DOS users, and it" _n
  372. "is the most convenient if the data you need is in Lotus, Symphony, dBase, "
  373. "Gauss" _n
  374. "SPSS, or SYSTAT formats.  It's called Stat/Transfer, an extra cost option" _n
  375. "available from us." _n(2)
  376. "We didn't write Stat/Transfer, but we do recommend it.  It's menu driven and"
  377. _n
  378. "at the touch of a key it will convert data from one software format to "
  379. "another." _n(12) ;
  380. drop _all ;
  381. label drop _all ;
  382.  
  383. drop _all ;
  384. label drop _all ;
  385. macro define F6 "do %path`intro.tut;";
  386. set more 0 ; more ; set more 1 ;
  387.  
  388. di _n(4) in white
  389. "Demonstration ends" _n
  390. "------------------" _n ;
  391.  
  392.  
  393. di in green
  394. "That concludes our short demonstration, but there's much more.  We now return"
  395. _n
  396. "control to you.  Some suggestions:" _n ;
  397.  
  398. di in green
  399. "If you ..." _col(34) "Then we will show you ..." _n
  400. "    Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
  401. "    Press " in white "F6" in green _col(38) "the first tutorial, "
  402. in white "intro.tut" _n ;
  403.  
  404. run %path`tobuy.tut ;
  405.